/*
 * gelifglcanvas.h
 *
 *  Created on: 2011-10-7
 *  Author    : gelif(admin@gelif.net)
 */
#ifndef GELIFGLCANVAS_H_
#define GELIFGLCANVAS_H_
class GeliFrame;
#ifndef GELIFRAME_H_
#include "geliframe.h"
#endif
#include <wx/glcanvas.h>
#include <wx/gdicmn.h>
#include <wx/image.h>
#include <gl/glu.h>
#include <stdlib.h>
#include <time.h>


class GelifGLCanvas: public wxGLCanvas
{
public:
    GelifGLCanvas(GeliFrame *geliFrame, wxWindow *parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition,
            const wxSize& size = wxDefaultSize);
    virtual ~GelifGLCanvas();

    // should be overwritten to draw something
    void draw();

    // Event Handlers (These Functions Should NOT be Virtual)
    // They are to be overwritten in the derived class as needed
    void onPaint(wxPaintEvent& event);
    void onLeftMouse(wxMouseEvent& event);
    void onEraseBackground(wxEraseEvent& event);
    void onIdle(wxIdleEvent& event);

    // specific methods
    void drawBoard();
    void drawPieces();
    void drawBlackPiece(int x, int y);
    void drawWhitePiece(int x, int y);
    void drawCircle(int x, int y, wxColour color);
    void drawFiveline();

    void getMouseBoardCoordinates();

    float getGLRed(wxColour &c);
    float getGLGreen(wxColour &c);
    float getGLBlue(wxColour &c);

    void setDefaultColors();
    void clearBoard(); // clears the board of pieces
    void setupBoard(); // sets up the board
    void sendMove(GelifMove &move);
    void updateEverybody();

    void onKeyDown(wxKeyEvent &event);

    // specific variables
    wxColour color_square;
    wxColour color_background;
    wxColour color_black_piece;
    wxColour color_white_piece;

    GeliFrame *geliFrame;

    // mouse location in terms of the board
    float x, y;

private:
    //DECLARE_CLASS(wxGLViewCanvas)
    wxGLContext* m_context;
    wxPoint point;
    const static double grid_width = 0.94;

    DECLARE_EVENT_TABLE()
    wxDECLARE_NO_COPY_CLASS(GelifGLCanvas);
};

#endif // _MYGLCANVAS_H__INCLUDED_
